package com.javaking.clanteam.studentutils.courses;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

import com.actionbarsherlock.app.SherlockDialogFragment;
import com.javaking.clanteam.studentutils.sql.CourseHelper;

public class RemoveCourseFragment extends SherlockDialogFragment {
	
	CourseData mCourse;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		mCourse = getArguments().getParcelable("course");
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		
		builder.setTitle("Are you sure?");
		builder.setMessage(String.format("Are you sure you want to remove %s from " +
				"your course list?",mCourse.getCourseTitle()));
		
		builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.cancel();
			}
		});
		
		builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				CourseHelper helper = new CourseHelper(getActivity());
				helper.dropCourse(mCourse);
				helper.close();
				dialog.cancel();
				getFragmentManager().popBackStack();
			}
		});
		
		return builder.create();
	}

}
